<? ini_set('memory_limit','500M');?>
<style>
body { margin-top:25; font-size:12px;}
		.b_line { border-bottom:1px #AAAAAA solid; height:25px; font-size:14px}
		.border_t{border-top:1px inset #EEE;}
		.border_b{border-bottom:1px inset #EEE;}
		.border_l{border-left:1px inset #EEE;}
		.border_r{border-right:1px inset #EEE;}
		.xx:hover {cursor:pointer; background:#99FF99;}
		.xy:hover {cursor:pointer; background:#F30;}
		.box{border:1px solid #003}
		.box_lbr{border:1px solid #003; border-top:none}
		.box_ltr{border:1px solid #003; border-bottom:none}
		.box_l{border-left:1px solid #003;}
		.box_r{border-right:1px solid #003;}
		.box_lb{border-left:1px solid #003;border-bottom:1px solid #003;}
		.box_rb{border-right:1px solid #003;border-bottom:1px solid #003;}
		.list_genap{cursor:pointer; background-color:#6699FF;}
		.list_ganjil{cursor:pointer; background-color:#9966FF;}
		.list_closed{cursor:pointer; background-color:#FF99FF;}
</style>
<table style='border-collapse:collapse' width='90%'>
	<tr align='center'><td colspan='2'><h2><?=$coy;?></h2><?=$add;?></td></tr>
	<tr align='center'><td colspan='2'><h1>RUGI LABA</h1></td></tr>
	<thead>
	<tr><td>Periode :<?=$from_tgl;?> s/d <?=$up_tgl;?></td><td colspan='10'>&nbsp;</td></tr>
	<tr class='box list_genap' align='center'>
		<th class='box' width='65%'>No. Perkiraan</th>
		<th class='box' width='25%'>Jumlah</th>
		<th class='box_l' style="background:#FFF" width='2%'></th>
	</tr>
	</thead>
	<? $n=0; $t_jml=0;
		   switch($lvl)
		   {
			   case '1':$ln=1;break;
			   case '2':$ln=5;break;
			   case '3':$ln=9;break;
			   case '4':$ln=13;break;
			   case '5':$ln=17;break;
		   }
		
		foreach($lst as $r)
		{
			$n++;
			$t_jml=($lvl!='1')?0:
			$this->main_model->rdb('v_jurnal',"(sum(debet)-sum(kredit)) as jml","where left(id_akun,1)='".$r->ckode."' and tgl_trans between '".tgltoSql($from_tgl)."' and '".tgltoSql($up_tgl)."' group by left(id_akun,1)"); 
		?>
			<tr class='box'>
			<td class='box'><font color="#FFFFFF"><?=str_repeat("x",(strlen($r->ckode)-1));?></font><?=$r->susunan;?></td>
			<td align='right' class='box'><?=number_format((int)$t_jml,0);?></td>
			<td class='box_l'>&nbsp;</td>
			</tr>
		<?
		   $jmle=0;$sb_jml=0;
		   $ordby=empty($_POST['ordby'])?'ckode':$_POST['ordby'];
		   $this->main_model->where(array('left(ckode,1)'=>$r->ckode));
		   $data=$this->main_model->generate_list('v_akun_display',$ordby);
		   foreach($data as $d)
		   {
			$jmle=$this->main_model->rdb('v_jurnal',"(sum(debet)-sum(kredit)) as jml","where left(id_akun,".$ln.")='".$d->ckode.
			"' and tgl_trans between '".tgltoSql($from_tgl)."' and '".tgltoSql($up_tgl)."' group by left(id_akun,".$ln.")"); 
			   ?>
			   <tr class='box'>
				<td class='box'><font color="#FFFFFF"><?=str_repeat("x",(strlen($d->ckode)-1));?></font><?=$d->susunan;?></td>
				<td align='right' class='box'><?=number_format((int)$jmle,0);?></td>
				<td class='box_l'>&nbsp;</td>
				</tr>
			   <?
			 $sb_jml +=$jmle;
			 $t_jml +=$jmle;
		   }
		   ?>
			<tr class='box'>
			<td class='box'><font color="#FFFFFF"><?=str_repeat("x",(strlen($r->ckode)-1));?></font><b>Sub Total(<?=$r->ckode;?>)</b></td>
			<td align='right' class='box'><?=number_format((int)$sb_jml,0);?></td>
			<td class='box_l'>&nbsp;</td>
			</tr>
	<?
		}
		?>
			<tr class='box'>
			<td align='right' class='box'><b>Rugi Laba Sebelum Pajak</b></td>
			<td align='right' class='box'><?=number_format((int)$t_jml,0);?></td><td class='box_l'>&nbsp;</td>
			</tr>
			<tr class='box'>
			<td align='right' class='box'><b>Pajak 10%</b></td>
			<td align='right' class='box'><?=number_format(((int)$t_jml*10/100),0);?></td><td class='box_l'>&nbsp;</td>
			</tr>
			<tr class='box'>
			<td align='right' class='box'><b>Rugi Laba Setelah Pajak</b></td>
			<td align='right' class='box'><?=number_format(((int)$t_jml-($t_jml*10/100)),0);?></td><td class='box_l'>&nbsp;</td>
			</tr>
			<? $kt=explode("-",$kota);?>
			<tr><td></td><td align='center'><?=$kt[0].", ". date('d F Y');?></td></tr>
			<tr><td height="50px">&nbsp;</td><td align='center' valign='top'><?='Keuangan,';?></td></tr>
			<tr><td></td><td align='center'><?=$keua;?></td></tr>
</table>
